﻿@model perfume.Models.ViewModels.ShoppingCartViewModel
@using System.Web.Mvc;
@{
    ViewBag.Title = "PERFUME WEB";
   
}
<script src="/Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(function () {
        // Document.ready -> link up remove event handler
        $(".RemoveLink").click(function () {
            // Get the id from the link
            var recordToDelete = $(this).attr("data-id");

            if (recordToDelete != '') {

                // Perform the ajax post
                $.post("/ShoppingCart/RemoveFromCart", { "id": recordToDelete },
                    function (data) {
                        // Successful requests get here
                        // Update the page elements
                        if (data.ItemCount == 0) {
                            $('#row-' + data.DeleteId).fadeOut('slow');
                        } else {
                            $('#item-count-' + data.DeleteId).text(data.ItemCount);
                        }

                        $('#cart-total').text(data.CartTotal);
                        //$('#update-message').text(data.Message);
                        $('#cart-status').text('Cart (' + data.CartCount + ')');
                       
                    });
            }
        });

    });


    function handleUpdate() {
        // Load and deserialize the returned JSON data
        var json = context.get_data();
        var data = Sys.Serialization.JavaScriptSerializer.deserialize(json);

        // Update the page elements
        if (data.ItemCount == 0) {
            $('#row-' + data.DeleteId).fadeOut('slow');
            
        } else {
            $('#item-count-' + data.DeleteId).text(data.ItemCount);
        }

        $('#cart-total').text(data.CartTotal);
        //$('#update-message').text(data.Message);
        $('#cart-status').text('Cart (' + data.CartCount + ')');
    }
</script>
<div class="Account-Module DefaultModule">
    <div class="Block">
        <div id="CartHeader" class="Block Moveable Panel">
            <h2>
                YOUR CART
            </h2>
        </div>
        <div id="CartContainer" class="Block Moveable Panel">
            <div class="BlockContent" id="update-message">
                <div style="">
                    <div>
                        <table class="CartContents" cellspacing="0" rules="rows" border="1" id="grvList"
                            style="width: 100%; border-collapse: collapse;">
                            <tbody>
                                <tr>
                                    <th align="left" scope="col">
                                        Product
                                    </th>
                                    <th scope="col">
                                        Quantity
                                    </th>
                                    <th align="right" scope="col">
                                        Price (đ)
                                    </th>
                                    <th align="right" scope="col">
                                        Sum (đ)
                                    </th>
                                    <th scope="col">
                                        &nbsp;
                                    </th>
                                </tr>
                                @foreach (var item in Model.CartItems)
                                {
                                    <tr id="row-@item.record_id">
                                        <td align="left">
                                            <a href="../../Home/Details/@item.product_id">@item.product.product_name
                                            </a>
                                        </td>
                                        <td align="center" style="width: 200px;" id="item-count-@item.record_id">
                                            <input name="txtAmount" type="text"
                                                value="@item.count" maxlength="3" 
                                                class="NormalTextBox" style="width: 45px;">
                                        </td>
                                        <td align="right" style="width: 70px;">
                                            @String.Format("{0:0,0 VNĐ}", Convert.ToInt32(item.product.price))
                                        </td>
                                        <td align="right" style="width: 150px;">
                                            <b>@String.Format("{0:0,0 VNĐ}", Convert.ToInt32(item.count * item.product.price))</b>
                                        </td>
                                        <td align="center" style="width: 150px;">
                                            @*<a href="#" class="RemoveLink" data-id="@item.record_id" onClick="document.location.reload(true)">DELETE</a>*@
                                            <a href="#" class="RemoveLink" data-id="@item.record_id" >DELETE</a>
                                            
                                        </td>
                                    </tr>
                                }
                                <tr>
                                        <td align="left">
                                            
                                        </td>
                                        <td align="center" style="width: 200px;" id="">
                                            
                                        </td>
                                        <td align="right" style="width: 70px;">
                                             Total:
                                        </td>
                                        <td align="right" style="width: 150px;">
                                            <p>
                                            <em class="ProductPrice">@String.Format("{0:0,0 VNĐ}", Convert.ToInt32(Model.CartTotal))</em></p>
                                        </td>
                                        <td align="center" style="width: 150px;">
                                            
                                        </td>
                                    </tr>


                              
                            </tbody>
                        </table>
                    </div>
                </div>
                <div class="Clear">
                    <div class="FloatRight">
                        @*<a href="#" class="RemoveLink" data-id="@Model.CartItems.Select(i => i.cart_id)">Xóa
                            giỏ hàng </a>*@
                        @using (Html.BeginForm("Send_export", "CheckOut", null, FormMethod.Post, new { id = "check-out" }))
                        {
              
                
                            <p>
                                <input type="submit" value="Send Order" />
                            </p>
                        }
                    </div>
                </div>
                <div class="Clear">
                </div>
            </div>
        </div>
    </div>
</div>
